home *** CD-ROM | disk | FTP | other *** search
- Path: peachy.apana.org.au!grahamb
- From: grahamb@peachy.apana.org.au (Graham Broadbridge)
- Newsgroups: comp.lang.c
- Subject: Re: Beginner needs advice about FILE I/O.
- Date: 10 Jan 1996 09:13:45 GMT
- Organization: The Peachy Linux Node!
- Message-ID: <4d0009$q73@peachy.apana.org.au>
- References: <4bu4i1$e0b@budapest.ozonline.com.au>
- NNTP-Posting-Host: peachy.apana.org.au
- X-Newsreader: TIN [version 1.2 PL2]
-
- cdowd@ozonline.com.au wrote:
- : I need to edit a file that consists of n number of a structure.
- : I can't see any way to directly delete files from a file stream
- : via it's FILE pointer. Is this possible?
-
- Not directly.
-
- : I could fread() the structures from the stream and make a linked
- : list or copy the structures between FILE pointers and not copy the
- : file to be deleted. Which would be better? What other alternatives
- : do I have?
-
- A simple method is to simply add a flag to the structure which
- indicates whether this record is deleted, and ignore the record during
- any subsequent processing.
-
- After a while (or prior to program termination) you could have a routine
- that compacts the file by reading in and subsequently writing out to a
- temp file all records for which the flag is false. Then copy the temp
- file over the original file, and then depending upon the success of the copy
- operation unlink the temp file.
-
- --
- +----------------------------------------------------------------------------+
- Graham Broadbridge Internet <graham@peachy.apana.org.au>
- Marsfield NSW <vk2yui@amsat.org>
- Australia amprnet <vk2yui@gw.vk2yui.ampr.org>
- +----------------------------------------------------------------------------+
-